package com.hsmpay.mobile.action.account.qian48;

import com.hsmpay.common.pojo.BasePojo;
import com.hsmpay.common.pojo.qian4.Qian4SendLog;
import com.hsmpay.common.util.DateConvertUtil;
import com.hsmpay.common.util.system.Constant;
import com.hsmpay.mobile.action.trans.TransBaseAction;
import com.hsmpay.mobile.ds.*;
import com.hsmpay.mobile.pojo.terminal.Tchannel;
import com.hsmpay.mobile.service.account.AccountManageQ4Service;
import com.hsmpay.mobile.service.terminal.TchannelService;
import com.hsmpay.mobile.service.trans.Qian4SendLogService;
import com.hsmpay.mobile.service.trans.TransRefuseCardService;
import com.hsmpay.qian4.service.ds.ZYTLPayService;
import org.apache.commons.lang.StringUtils;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 千48基础 action
 *
 * @author 颜铃璋
 * @date 2013-8-27
 */
public class Q4BaseAction extends TransBaseAction {
    protected static final long serialVersionUID = -7639808245478070819L;
    public static final String MERCHANT_NAME = "北京中亿腾乐有限公司";//商户名称
    public static final String MERCHANT_ID = "137458000000002";//商户编号
    public static final String TERMINAL_ID_FL = "60001"; //费率版终端号
    public static final String TERMINAL_ID_FD = "60002"; //封顶版终端号

    public static final String masterKey = "235E8FFCF30EFAA3EE95B2DC672559DA"; //主密钥 (密文)
    public static final String pinKey = "8743E08BBF94D45EC8FBEBF053B16581";    //pin密钥 (密文)
    public static final String trackKey = "DF012551A472C274AFDD405C80CF929A";  //磁道密钥 (密文)
    public static final String hdybtzKey = "070C99CCCAB462F3D42AA0463A9A9265"; //回调异步通知密钥 (密文)


    public static final String ERROR_STR = "0";
    //public static final String Certificate = "c/";//小票 base路径
    public static final String Certificate = Constant.getAttribute("CERTIFICATE_BASE_URL") + "c.action?d=";//小票 base路径
    public static final double q4FeeRate = 0.0040;//千四费率
    public static final double lyjFDFeeRate = 0.0035;

    public static final double q4BackFDMoney = 20;//千四封顶金额
    //public static final double fDMoney = 30;//封顶金额
    //public static final double fDMinMoney = 2;//封顶金额
    public static final double minRevenueFeeMoney = 0.0;//0.08;//最低渠道商手续费

//    public static final String pinKey = null;//PIN密钥(密文)
    public static final String DesKey = null;//MAC密钥(密文)
    public static final String macKey = null;//传输报文加密密钥(密文)


    protected String application;//M 应用名称
    protected String transType;
    protected String sendTime;//M 发送时间 yyyyMMddHHmmss
    protected String sendSeqId;//M 发送流水ID 只有六位数字  标识报文发送的唯一编号，可以循环，要求至少在一天内唯一
    protected String terminalId;//M 终端代码 118910100062
    protected String platformId = "1";//M 平台代码

    protected String transId;//C 交易流水号
    protected String merchantOrderId;//C 商户订单号
    protected String merchantOrderTime;//商户订单时间
    protected String transAmt;//M 交易金额
    protected String transTime;//C 交易日期 N(14)
    protected String currency;//M 交易币种

    protected String accountNumber;//主账户
    protected String pin;//个人身份标识码
    protected String track2Data;//M 磁道2数据 40
    protected String track3Data;//M 磁道3数据
    protected String cardholderSign;//C 电子签名
    protected String dynamicKeyData;//M 动态密钥数据 16

    protected String merchantSign;//C 商户数字签名
    protected String senderSign;//C 发送方数字签名
    protected String serviceInfo;//C 服务信息
    protected String terminalInfo;//C 终端信息 手机串号、号码、os、序列号等
    protected String mac;//M 报文鉴别码

    protected String picBuffer;//图片流
    protected Long receivablesId;//订单ID

    protected String creditNumber;//信用卡卡号
    protected String accountNumber2;//转入卡卡号
    protected String accountName;//转入账户名
    protected String phoneNum;//待充值手机号
    protected String signaturePath;//待充值手机号

    protected String icCardNum;//IC卡序号
    protected String icCardYu;//IC卡域
    protected String encryType;//加密方式
    protected String transTerminalId;//交易终端ID（翰星）

    protected String orgMerchantOrderId;//

    @Resource(name = "transRefuseCardService")
    protected TransRefuseCardService<BasePojo, Long> transRefuseCardService;//拒绝卡号交易
    @Resource(name = "qian4SendLogService")
    protected Qian4SendLogService<Qian4SendLog, Long> qian4SendLogService;//发送日志
    @Resource(name = "accountManageQ4Service")
    protected AccountManageQ4Service<BasePojo, Long> accountManageQ4Service;

    @Resource(name = "tchannelService")
    public TchannelService<Tchannel, Long> tchannelService;

    @Resource(name = "ds_ECBService")
    public DS_ECBService<BasePojo, Long> ds_ECBService;//ECB
    @Resource(name = "ds_RuiShengService")
    public DS_RuiShengService<BasePojo, Long> ds_RuiShengService;//瑞升
    @Resource(name="ds_RuiShengGTService")
    public DS_RuiShengGTService<BasePojo,Long> ds_RuiShengGTService;//瑞晟国通
    @Resource(name = "posPService")
    public DS_POSPService<BasePojo,Long> ds_pospService;//pos
    @Resource(name = "ds_IdeaioeService")
    public DS_IdeaioeService<BasePojo,Long> ds_ideaioeService;//E点
    @Resource(name = "ds_zytlPayService")
    public ZYTLPayService ds_zytlPayService;
    @Resource(name = "ds_UinpayPayService")
    public DS_UinpayPayService<BasePojo,Long> ds_uinpayPayService;//优银
    @Resource(name="ds_YinShengBaoService")
    public DS_YinShengBaoService<BasePojo,Long> ds_yinShengBaoService;//银生宝
    @Resource(name = "ds_posService")
    public DS_POSService<BasePojo,Long> ds_posService;//大pos
    @Resource(name = "ds_ZHIFUTONGService")
    public DS_ZHIFUTONGService<BasePojo,Long> ds_zhifutongService;//支付通
    @Resource(name = "ds_HanXinService")
    public DS_HanXinService<BasePojo, Long> ds_HanXinService;//翰鑫
    @Resource(name = "DS_ZhongLanService")
    public DS_ZhongLanService<BasePojo,Long> ds_zhongLanService;//中岚
    @Resource(name = "DS_KaYinKaService")
    public DS_KaYinKaService<BasePojo,Long> ds_kaYinKaService;//卡银卡


    /**
     * 生产 商户订单号
     *
     * @param mobile
     * @return
     */
    protected String getMerchantOrderId(Date date, String mobile) {
        String end = "";
        if (StringUtils.isNotBlank(mobile)) {
            end = mobile.substring(mobile.length() - 6);
        }
        StringBuilder sb = new StringBuilder();
        String orderId = DateConvertUtil.dateString(date, "yyyyMMddHHmmssSSS");
        return sb.append(orderId).append(end).toString();
    }

    //---------------------set get start--------------------

    public void setTransId(String transId) {
        this.transId = transId;
    }

    public void setMerchantOrderId(String merchantOrderId) {
        this.merchantOrderId = merchantOrderId;
    }

    public void setTransAmt(String transAmt) {
        this.transAmt = transAmt;
    }

    public void setTransTime(String transTime) {
        this.transTime = transTime;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }

    public void setAccountNumber(String accountNumber) {
        this.accountNumber = accountNumber;
    }

    public void setPin(String pin) {
        this.pin = pin;
    }

    public void setTrack2Data(String track2Data) {
        this.track2Data = track2Data;
    }

    public void setTrack3Data(String track3Data) {
        this.track3Data = track3Data;
    }

    public void setCardholderSign(String cardholderSign) {
        this.cardholderSign = cardholderSign;
    }

    public void setDynamicKeyData(String dynamicKeyData) {
        this.dynamicKeyData = dynamicKeyData;
    }

    public void setMerchantSign(String merchantSign) {
        this.merchantSign = merchantSign;
    }

    public void setSenderSign(String senderSign) {
        this.senderSign = senderSign;
    }

    public void setServiceInfo(String serviceInfo) {
        this.serviceInfo = serviceInfo;
    }

    public void setTerminalInfo(String terminalInfo) {
        this.terminalInfo = terminalInfo;
    }

    public void setMac(String mac) {
        this.mac = mac;
    }

    public void setTerminalId(String terminalId) {
        this.terminalId = terminalId;
    }

    public void setPicBuffer(String picBuffer) {
        this.picBuffer = picBuffer;
    }

    public void setReceivablesId(Long receivablesId) {
        this.receivablesId = receivablesId;
    }

    public String getMerchantOrderId() {
        return merchantOrderId;
    }

    public void setMerchantOrderTime(String merchantOrderTime) {
        this.merchantOrderTime = merchantOrderTime;
    }

    public void setFunctionKey(String functionKey) {
        this.functionKey = functionKey;
    }

    public void setCreditNumber(String creditNumber) {
        this.creditNumber = creditNumber;
    }
    //---------------------set get end----------------------


    public void setAccountNumber2(String accountNumber2) {
        this.accountNumber2 = accountNumber2;
    }


    public void setAccountName(String accountName) {
        this.accountName = accountName;
    }


    public void setOrgMerchantOrderId(String orgMerchantOrderId) {
        this.orgMerchantOrderId = orgMerchantOrderId;
    }


    public void setClientType(Integer clientType) {
        this.clientType = clientType;
    }

    public String getEncryType() {
        return encryType;
    }

    public void setEncryType(String encryType) {
        this.encryType = encryType;
    }
}
